<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>钻石投票_公众号设置</title>
    <link rel="stylesheet" type="text/css" href="__MCSS__/bass.css">
    <link rel="stylesheet" type="text/css" href="__CSS__/font-awesome.css">
    <link rel="stylesheet" href="__MCSS__/wechat_set.css">
</head>
<body>

<div class="WeChat-set">

    <div class="WeChat-main">

        <p class="WeChat-set-tit"><span class="span1">系统设置</span><i class="fa fa-caret-right"></i><span class="span2">公众号设置</span></p>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">公众号名称：</p>
            <input type="text" name="" id="wechat_name" value="{$config_array['wechat_name'] ?? ''}">
        </div>

        <div class="WeChat-list2">
            <p class="WeChat-list-tit">公众号二维码：</p>
            <div class="WeChat-upload">
                <div class="WeChat-upload-img"><img src="{notempty name='$config_array.wechat_qrcode'} {$config_array.wechat_qrcode} {else} __MIMG__/qrcode.jpg {/notempty}"></div>
                <p class="lcg-btn5 WeChat-upload-btn"><input type="file" name="" id="wechat_qrcode"><span>上传图片</span></p>
            </div>
        </div>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">AppID：</p>
            <input type="text" name="" id="wechat_appid" value="{$config_array['wechat_appid'] ?? ''}">
        </div>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">AppSecret：</p>
            <input type="text" name="" id="wechat_secret" value="{$config_array['wechat_secret'] ?? ''}">
        </div>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">微支付商户号：</p>
            <input type="text" name="" id="wechat_mercode" value="{$config_array['wechat_mercode'] ?? ''}">
        </div>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">微支付API密钥：</p>
            <input type="text" name="" id="wechat_merkey" value="{$config_array['wechat_merkey'] ?? ''}">
        </div>

        <div class="WeChat-list">
            <p class="WeChat-list-tit">微信验证文件名称:</p>
            <input type="text" name="" id="wechat_rulename" value="{$config_array['wechat_rulename'] ?? ''}">
            <div class="WeChat-submit">提交</div>
        </div>

        <div class="lcg-btn5 WeChat-set-btn">保存</div>

    </div>

</div>

</body>

<!-- 页面加载 -->
<div class="cloud-set-loading" style="display: none;"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div>

<script src="__JS__/jquery_v3.3.1.js"></script>
<script src="__JS__/layer/layer.js"></script>
<script src="__JS__/common.js"></script>

<script type="text/javascript">
    var image = '';

    $(function () {
        var state = 0,
            set_state = 0;
        // 点击保存按钮
        $('.WeChat-set-btn').on('click', function () {
            //防止频繁提交
            if (set_state === 1) {
                return false;
            }
            set_state = 1;
            setTimeout(function () {
                set_state = 0;
            }, 1000);
            //提交数据
            var json = {
                'wechat_name': $("#wechat_name").val(),
                'wechat_appid': $("#wechat_appid").val(),
                'wechat_secret': $("#wechat_secret").val(),
                'wechat_qrcode': image,
                'wechat_mercode': $("#wechat_mercode").val(),
                'wechat_rulename': $("#wechat_rulename").val(),
                'wechat_merkey': $("#wechat_merkey").val()
            };
            $(".cloud-set-loading").show();
            $.post("/admin/system/setConfig", json, function (result) {
                $(".cloud-set-loading").hide();
                if (result) {
                    layer.msg('保存成功');
                } else {
                    layer.msg('保存失败');
                }
            });
        });

        // 提交微信验证文件
        $('.WeChat-submit').click(function () {
            if (state === 1) {
                return false;
            }
            state = 1;
            setTimeout(function () {
                state = 0;
            }, 1000);
            $(".cloud-set-loading").show();
            $.post("/admin/system/createTxt", {"file_name": '2'}, function (result) {
                $(".cloud-set-loading").hide();
                if (result == false) {
                    layer.msg('提交失败,请重试');
                    return false;
                }
                layer.msg('已提交');
            });
        });

        //公众号二维码图片上传
        $("#wechat_qrcode").on("change", function () {
            //图像转Base64
            imgBase64($(this)[0], function (imgString) {
                $(".cloud-set-loading").show();
                $.post("/admin/system/base64Image", {"imgString": imgString}, function (con) {
                    $(".cloud-set-loading").hide();
                    con = $.parseJSON(con);
                    if (con.state == 1) {
                        image =  con.url;
                        $(".WeChat-upload-img > img").prop("src", con.url);
                    } else {
                        layer.msg(con.state);
                    }
                }, 'json');
            });
        });

    });


</script>

</html>

